﻿using System;
using System.Diagnostics;
using Ninject.Extensions.Interception;

namespace NInject.Practice.Interceptor
{
    public class TimingInterceptor : SimpleInterceptor
    {
        readonly Stopwatch _stopwatch = new Stopwatch();

        protected override void BeforeInvoke(IInvocation invocation)
        {
            _stopwatch.Start();
            Console.WriteLine("start");
        }

        protected override void AfterInvoke(IInvocation invocation)
        {
            _stopwatch.Stop();
            string message = string.Format("Execution of {0} took {1}.",
                invocation.Request.Method,
                _stopwatch.Elapsed);
            Console.WriteLine(message);
            _stopwatch.Reset();
        }
    }
}